home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / plane / _Point1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  3.3 KB  |  164 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _Point1.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <math.h>
  16. #include <ctype.h>
  17. #ifdef AMIGA
  18. #    include <LEDA/_Point1.h>
  19. #else
  20. #    include <LEDA/Point1.h>
  21. #endif
  22.  
  23. //------------------------------------------------------------------------------
  24. // Points 
  25. //------------------------------------------------------------------------------
  26.  
  27.  
  28. Point_rep::Point_rep()  { count=1; x = y = 0; w = 1;}
  29.  
  30. Point_rep::Point_rep(Int a, Int b) 
  31. { x = a; 
  32.   y = b;
  33.   w = 1; 
  34.   count = 1; 
  35. }
  36.  
  37.  
  38. Point_rep::Point_rep(Int a, Int b, Int c) 
  39. { x = a; 
  40.   y = b;
  41.   w = c; 
  42.   count = 1; 
  43. }
  44.  
  45. Point::Point()                  { PTR = new Point_rep; }
  46. Point::Point(Int x, Int y){ PTR = new Point_rep(x,y); }
  47. Point::Point(Int x, Int y, Int w){ PTR = new Point_rep(x,y,w); }
  48.  
  49. //Point::Point(vector v)          { PTR = new Point_rep(v[0], v[1]); }
  50.  
  51. /*
  52. double Point::angle(const Point& q, const Point& r) const
  53. {
  54.   double cosfi,fi,norm;
  55.   
  56.   double dx  = q.ptr()->x - ptr()->x; 
  57.   double dy  = q.ptr()->y - ptr()->y; 
  58.  
  59.   double dxs = r.ptr()->x - q.ptr()->x; 
  60.   double dys = r.ptr()->y - q.ptr()->y; 
  61.   
  62.   cosfi=dx*dxs+dy*dys;
  63.   
  64.   norm=(dx*dx+dy*dy)*(dxs*dxs+dys*dys);
  65.  
  66.   cosfi /= sqrt( norm );
  67.  
  68.   if (cosfi >=  1.0 ) return 0;
  69.   if (cosfi <= -1.0 ) return M_PI;
  70.   
  71.   fi=acos(cosfi);
  72.  
  73.   if (dx*dys-dy*dxs>0) return fi;
  74.  
  75.   return -fi;
  76. }
  77.   
  78.  
  79. Point Point::rotate(const Point& origin, double alpha) const
  80. { if (origin == *this) return *this;
  81.   segment s(origin,*this);
  82.   return s.rotate(alpha).end();
  83. }
  84.  
  85. Point Point::rotate(double alpha) const
  86. { return rotate(Point(0,0),alpha); }
  87.  
  88. Point Point::translate(double alpha, double d) const
  89. { double dx = cos(alpha) * d;
  90.   double dy = sin(alpha) * d;
  91.   return Point(ptr()->x+dx,ptr()->y+dy);
  92.  }
  93.  
  94. Point Point::translate(const vector& v) const
  95. { return Point(ptr()->x+v[0],ptr()->y+v[1]);
  96.  }
  97.  
  98. double Point::distance(const Point& p)  const
  99. { return hypot(p.ptr()->x - ptr()->x, p.ptr()->y - ptr()->y); } 
  100.  
  101. double Point::distance() const
  102. { return distance(Point(0,0)); }
  103. */
  104.  
  105.  
  106. int Point::operator==(const Point& p) const 
  107. { return ( (((ptr()->x) * (p.ptr()->w) - (p.ptr()->x) * (ptr()->w)) == 0) && 
  108. (((ptr()->y) * (p.ptr()->w) - (p.ptr()->y) * (ptr()->w)) == 0)); }
  109.  
  110.  
  111. ostream& operator<<(ostream& out, const Point& p)
  112. { out << "(" << p.X() << "," << p.Y() << "," << p.W() << ")";
  113.   return out;
  114.  } 
  115.  
  116. istream& operator>>(istream& in, Point& p) 
  117. { // syntax: {(} x {,} y {,} w {)}   
  118.  
  119.   int x,y,w;
  120.   char c;
  121.  
  122.   do in.get(c); while (in && isspace(c));
  123.  
  124.   if (!in) return in;
  125.  
  126.   if (c != '(') in.putback(c);
  127.  
  128.   in >> x;
  129.  
  130.   do in.get(c); while (isspace(c));
  131.   if (c != ',') in.putback(c);
  132.  
  133.   in >> y; 
  134.  
  135.   do in.get(c); while (isspace(c));
  136.   if (c != ',') in.putback(c);
  137.  
  138.   in >> w; 
  139.  
  140.   do in.get(c); while (c == ' ');
  141.   if (c != ')') in.putback(c);
  142.  
  143.   p = Point(x,y,w ); 
  144.   return in; 
  145.  
  146.  } 
  147.  
  148. /*
  149. int compare(const Point& a, const Point& b)
  150. { Int x = a.X() * b.W();
  151.   Int y = b.X() * a.W();
  152.   int s = sign(a.W()) * sign(b.W());
  153.   if (x == y) 
  154.   { x = a.Y() * b.W();
  155.     y = b.Y() * a.W();
  156.     if (x == y) return 0;
  157.    }
  158.   return (x < y) ? -s : s;
  159. }
  160. */
  161.  
  162.  
  163.